Completed
Push — master ( 809444...363a27 )
by Maxence
05:40 queued 02:26
created

elements.fillMembersSearch   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
/** global: Notyf */
29
30
/** global: nav */
31
/** global: actions */
32
/** global: curr */
33
/** global: api */
34
35
36
var elements = {
37
38
	newTypeDefinition: null,
39
	newType: null,
40
	newSubmit: null,
41
	newName: null,
42
	navigation: null,
43
	circlesList: null,
44
	circlesSearch: null,
45
	circlesFilters: null,
46
	circlesDetails: null,
47
	emptyContent: null,
48
	mainUI: null,
49
	mainUIMembers: null,
50
	membersSearchResult: null,
51
	memberDetails: null,
52
	memberRequest: null,
53
54
	joinCircleInteraction: null,
55
	joinCircleAccept: null,
56
	joinCircleReject: null,
57
	joinCircleRequest: null,
58
	joinCircleInvite: null,
59
	joinCircle: null,
60
	leaveCircle: null,
61
	destroyCircle: null,
62
63
	rightPanel: null,
64
	addMember: null,
65
	remMember: null,
66
	linkCircle: null,
67
68
	buttonCircleActions: null,
69
	buttonCircleActionReturn: null,
70
	buttonCircleSettings: null,
71
	buttonAddMember: null,
72
	buttonLinkCircle: null,
73
74
75
	initElements: function () {
76
77
		elements.newTypeDefinition = $('#circles_new_type_definition');
78
		elements.newType = $('#circles_new_type');
79
		elements.newSubmit = $('#circles_new_submit');
80
		elements.newName = $('#circles_new_name');
81
		elements.navigation = $('#app-navigation.circles');
82
		elements.circlesList = $('#circles_list');
83
		elements.circlesSearch = $('#circles_search');
84
		elements.circlesFilters = $('#circles_filters');
85
		elements.circlesDetails = $('#circle_details');
86
		elements.emptyContent = $('#emptycontent');
87
		elements.mainUI = $('#mainui');
88
		elements.mainUIMembers = $('#memberslist_table');
89
		elements.membersSearchResult = $('#members_search_result');
90
		elements.memberDetails = $('#memberdetails');
91
		elements.memberRequest = $('#member_request');
92
93
		elements.joinCircleInteraction = $('#sjoincircle_interact');
94
		elements.joinCircleAccept = $('#joincircle_acceptinvit');
95
		elements.joinCircleReject = $('#joincircle_rejectinvit');
96
		elements.joinCircleRequest = $('#joincircle_request');
97
		elements.joinCircleInvite = $('#joincircle_invit');
98
		elements.joinCircle = $('#joincircle');
99
		elements.leaveCircle = $('#leavecircle');
100
		elements.destroyCircle = $('#circle-actions-delete');
101
102
		elements.rightPanel = $('#rightpanel');
103
		elements.addMember = $('#addmember');
104
		elements.remMember = $('#remmember');
105
		elements.linkCircle = $('#linkcircle');
106
107
		elements.buttonCircleActions = $('#circle-actions-buttons');
108
		elements.buttonCircleActionReturn = $('#circle-actions-return');
109
		elements.buttonCircleSettings = $('#circle-actions-settings');
110
		elements.buttonAddMember = $('#circle-actions-add');
111
		elements.buttonLinkCircle = $('#circle-actions-link');
112
		elements.buttonJoinCircle = $('#circle-actions-join');
113
	},
114
115
116
	initTweaks: function () {
117
		$.fn.emptyTable = function () {
118
			this.children('tr').each(function () {
119
				if ($(this).attr('class') !== 'header') {
120
					$(this).remove();
121
				}
122
			});
123
		};
124
	},
125
126
127
	initUI: function () {
128
		elements.newTypeDefinition.children('div').fadeOut(0);
129
		$('#circles_new_type_' + elements.newType.children('option:selected').val()).fadeIn(
130
			0);
131
132
		elements.newType.hide();
133
		elements.newSubmit.hide();
134
		elements.newTypeDefinition.hide();
135
136
		$('.icon-circles').css('background-image',
137
			'url(' + OC.imagePath('circles', 'colored') + ')');
138
139
		var theme = $('#body-user').find('#header').css('background-color');
140
		elements.circlesList.css('background-color', theme);
141
		elements.circlesDetails.css('background-color', theme);
142
		elements.rightPanel.css('background-color', theme);
143
144
		elements.membersSearchResult.hide();
145
	},
146
147
148
	/**
149
	 *
150
	 */
151
	initExperienceCirclesList: function () {
152
153
		elements.circlesList.children('div').on('click', function () {
154
			nav.displayCirclesList($(this).attr('circle-type'));
155
		});
156
157
		this.initExperienceCirclesListFromSearch();
158
		this.initExperienceCirclesListFromFilter();
159
	},
160
161
162
	initExperienceCirclesListFromSearch: function () {
163
164
		this.circlesSearch.on('input property paste focus', function () {
165
			var search = $(this).val().trim();
166
			if (curr.searchCircle === search) {
167
				return;
168
			}
169
170
			curr.searchCircle = search;
171
			api.searchCircles(curr.circlesType, curr.searchCircle, curr.searchFilter,
172
				actions.listCirclesResult);
173
		});
174
	},
175
176
177
	initExperienceCirclesListFromFilter: function () {
178
179
		this.circlesFilters.on('input property paste focus', function () {
180
			var searchFilter = $(this).val();
181
			if (curr.searchFilter === searchFilter) {
182
				return;
183
			}
184
185
			curr.searchFilter = searchFilter;
186
			api.searchCircles(curr.circlesType, curr.searchCircle, curr.searchFilter,
187
				actions.listCirclesResult);
188
		});
189
190
	},
191
192
193
	/**
194
	 *
195
	 */
196
	initExperienceCircleButtons: function () {
197
198
		elements.buttonCircleActionReturn.hide();
199
		elements.buttonCircleActionReturn.on('click', function () {
200
			nav.circlesActionReturn();
201
		});
202
203
		elements.buttonAddMember.on('click', function () {
204
			nav.displayCircleButtons(false);
205
			nav.displayAddMemberInput(true);
206
			nav.displayLinkCircleInput(false);
207
			nav.displayJoinCircleButton(false);
208
		});
209
210
		elements.buttonLinkCircle.on('click', function () {
211
			nav.displayCircleButtons(false);
212
			nav.displayAddMemberInput(false);
213
			nav.displayLinkCircleInput(true);
214
			nav.displayJoinCircleButton(false);
215
		});
216
217
		elements.buttonJoinCircle.on('click', function () {
218
			nav.joinCircleAction();
219
		});
220
221
222
223
	},
224
225
226
	/**
227
	 *
228
	 */
229
	initAnimationNewCircle: function () {
230
231
		elements.newName.on('keyup', function () {
232
			actions.onEventNewCircleName();
233
		});
234
235
		elements.newType.on('change', function () {
236
			actions.onEventNewCircleType();
237
		});
238
239
		elements.newSubmit.on('click', function () {
240
			api.createCircle(elements.newType.val(), elements.newName.val(),
241
				actions.createCircleResult);
242
		});
243
244
	},
245
246
247
	emptyCircleCreation: function () {
248
		elements.newName.val('');
249
		elements.newType.val('');
250
	},
251
252
	fillMembersSearch: function (exact, partial) {
253
		this.fillExactMembersSearch(exact);
254
		this.fillPartialMembersSearch(partial);
255
		elements.membersSearchResult.children().first().css('border-top-width', '0px');
256
	},
257
258
259
	fillExactMembersSearch: function (exact) {
260
261
		$.each(exact, function (index, value) {
262
			elements.membersSearchResult.append(
263
				'<div class="members_search exact" searchresult="' +
264
				escapeHTML(value.value.shareWith) + '">' + escapeHTML(value.label) + '   (' +
265
				escapeHTML(value.value.shareWith) + ')</div>');
266
		});
267
268
	},
269
270
271
	fillPartialMembersSearch: function (partial) {
272
		$.each(partial, function (index, value) {
273
			var currSearch = elements.addMember.val().trim();
274
			var line = escapeHTML(value.label) + '   (' + escapeHTML(value.value.shareWith) + ')';
275
			if (currSearch.length > 0) {
276
				line = line.replace(new RegExp('(' + currSearch + ')', 'gi'), '<b>$1</b>');
277
			}
278
279
			elements.membersSearchResult.append(
280
				'<div class="members_search" searchresult="' + escapeHTML(value.value.shareWith) +
281
				'">' + line +
282
				'</div>');
283
		});
284
285
	},
286
287
288
	resetCirclesList: function () {
289
290
		elements.navigation.addClass('selected');
291
		elements.navigation.children().each(function () {
292
			if ($(this).attr('id') !== 'circles_search' &&
293
				$(this).attr('id') !== 'circles_filters') {
294
				$(this).remove();
295
			}
296
		});
297
	},
298
299
300
	removeMemberslistEntry: function (membername) {
301
		this.mainUIMembers.children("[member-id='" + escapeHTML(membername) + "']").each(
302
			function () {
303
				$(this).hide(300);
304
			});
305
	},
306
307
308
	generateTmplCircle: function (entry) {
309
		var tmpl = $('#tmpl_circle').html();
310
311
		tmpl = tmpl.replace(/%title%/g, escapeHTML(entry.name));
312
		tmpl = tmpl.replace(/%type%/g, t('circles', escapeHTML(entry.type)));
313
		tmpl = tmpl.replace(/%owner%/g, escapeHTML(entry.owner.user_id));
314
		tmpl = tmpl.replace(/%status%/g, t('circles', escapeHTML(entry.user.status)));
315
		tmpl = tmpl.replace(/%level_string%/g, t('circles', escapeHTML(entry.user.level_string)));
316
		tmpl = tmpl.replace(/%creation%/g, escapeHTML(entry.creation));
317
318
		return tmpl;
319
	},
320
321
322
	generateTmplMember: function (entry) {
323
		var tmpl = $('#tmpl_member').html();
324
325
		tmpl = tmpl.replace(/%username%/g, escapeHTML(entry.user_id));
326
		tmpl = tmpl.replace(/%level%/g, escapeHTML(entry.level));
327
		tmpl = tmpl.replace(/%status%/g, escapeHTML(entry.status));
328
		tmpl = tmpl.replace(/%joined%/g, escapeHTML(entry.joined));
329
330
		return tmpl;
331
	}
332
333
334
};